import { defHttp } from "/@/utils/http/axios"
import { getPermissionResultModel } from "./model/menuModel"
import { Modal } from "ant-design-vue"

/**
 * @description: Get user menu based on id
 */
export const getPermission = () => {
  // 获取系统权限
  // 1、查询用户拥有的按钮/表单访问权限
  // 2、所有权限
  // 3、系统安全模式
  return defHttp.get<getPermissionResultModel>({ url: `/iam-service/user/me/getPermission` })
}


/**
 * 删除菜单
 */
export const deleteMenu = (params, handleSuccess) => {
  const adminFlag = params.adminFlag
  delete params.adminFlag
  const url = adminFlag ? "/iam-service/system/menu/delete" : "/iam-service/manage/menu/delete"
  return defHttp.delete({ url, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}


/**
 * 批量删除菜单
 * @param params
 */
export const batchDeleteMenu = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/iam-service/manage/menu/deleteBatch", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}


/**
 * 拷贝菜单
 */
export const copyMenu = (params, handleSuccess) => {
  return defHttp.post({ url: "/iam-service/manage/menu/copyMenu", params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}
